var mdata = {
		
	// 封装获取Jsgx Mobile Data 的 URL
	URL : {
		jsgxMobileData : function(typeId, saleAttr) {
			return '/wexin_info/' + saleAttr + '/' + typeId + '/getData';
		},
	},
	
	// 格式化数字
	format : {
		number : function (number, decimals, dec_point, thousands_sep) {
			 /*
			 3     * 参数说明：
			 4     * number：要格式化的数字
			 5     * decimals：保留几位小数
			 6     * dec_point：小数点符号
			 7     * thousands_sep：千分位符号
			 8     * */
			 number = (number + '').replace(/[^0-9+-Ee.]/g, '');
			 var n = !isFinite(+number) ? 0 : +number,
			 prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
			 sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
			 dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
			 s = '',
			 toFixedFix = function (n, prec) {
				 var k = Math.pow(10, prec);
			 	return '' + Math.ceil(n * k) / k;
			 };
			 
			 s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
			 var re = /(-?\d+)(\d{3})/;
			 while (re.test(s[0])) {
			 	s[0] = s[0].replace(re, "$1" + sep + "$2");
			 }
			 
			 if ((s[1] || '').length < prec) {
				 s[1] = s[1] || '';
				 s[1] += new Array(prec - s[1].length + 1).join('0');
			 }
			 return s.join(dec);
		}
	},

	// 获取数据逻辑
	detail : {
		getData : function (params) {
			var typeId = params['typeId'];
			var saleAttr = params['saleAttr'];
			var tblType = params['type'];
			var dataType = params['dataType'];
			$.get(mdata.URL.jsgxMobileData(typeId, saleAttr), {}, function(result) {
				if (result && result['code']) {
					dataContent = result['data']['list'];
					mdata.content.create(dataContent, tblType, dataType);
				} else {
					console.log(result);
				}
			})
		}
	},
	
	// 创建 html 列表
	content : {
		create : function (data, tblType, detail) {
			var list = $('#list');
			list.empty();
			var _arr = [];
			
			if (tblType == 0) {
				//隐藏按钮
				$('#btnList').css('display','none');
				
				//json 遍历
				for (ele in data) {
					var yearRate = mdata.format.number(data[ele].yearRate, 2, ".", ",");
					var monRate = mdata.format.number(data[ele].monRate, 2, ".", ",");
					var dayBzamt = mdata.format.number(data[ele].dayBzamt, 2, ".", ",");
					var dayAmt = mdata.format.number(data[ele].dayAmt, 2, ".", ",");
					var monBzamt = mdata.format.number(data[ele].monBzamt, 2, ".", ",");
					var monBzamtRate = mdata.format.number(data[ele].monBzamtRate, 2, ".", ",");
					var monAmt = mdata.format.number(data[ele].monAmt, 2, ".", ",");
					var monAmtRate = mdata.format.number(data[ele].monAmtRate, 2, ".", ",");
					var yearBzamt = mdata.format.number(data[ele].yearBzamt, 2, ".", ",");
					var yeaBzamtRate = mdata.format.number(data[ele].yeaBzamtRate, 2, ".", ",");
					var yeaAmt = mdata.format.number(data[ele].yeaAmt, 2, ".", ",");
					var yeaAmtRate = mdata.format.number(data[ele].yeaAmtRate, 2, ".", ",");
				
					var _html = `<li><p>本年标保达成率</p><p class="ui-li-aside">${yearRate}%</p></li>
								 <li><p>本月标保达成率</p><p class="ui-li-aside">${monRate}%</p></li>
								 <li><p>本日标保</p><p class="ui-li-aside">${dayBzamt}</p></li>
								 <li><p>本日新保</p><p class="ui-li-aside">${dayAmt}</p></li>
								 <li><p>本月标保/同比</p><p class="ui-li-aside">${monBzamt}/${monBzamtRate}%</p></li>
								 <li><p>本月新保/同比</p><p class="ui-li-aside">${monAmt}/${monAmtRate}%</p></li>
								 <li><p>本年标保/同比</p><p class="ui-li-aside">${yearBzamt}/${yeaBzamtRate}%</p></li>
								 <li><p>本年新保/同比</p><p class="ui-li-aside">${yeaAmt}/${yeaAmtRate}%</p></li>`;
					
//					var _html = '<li><p>本年标保达成率</p><p class="ui-li-aside">' + yearRate + '%</p></li>' + 
//					'<li><p>本月标保达成率</p><p class="ui-li-aside">' + monRate + '%</p></li>' +
//					'<li><p>本日标保</p><p class="ui-li-aside">' + dayBzamt + '</p></li>' + 
//					'<li><p>本日新保</p><p class="ui-li-aside">' + dayAmt + '</p></li>' + 
//					'<li><p>本月标保/同比</p><p class="ui-li-aside">' + monBzamt + '/' + monBzamtRate + '%</p></li>' + 
//					'<li><p>本月新保/同比</p><p class="ui-li-aside">' + monAmt + '/' + monAmtRate + '%</p></li>' + 
//					'<li><p>本年标保/同比</p><p class="ui-li-aside">' + yearBzamt + '/' + yeaBzamtRate + '%</p></li>' + 
//					'<li><p>本年新保/同比</p><p class="ui-li-aside">' + yeaAmt + '/' + yeaAmtRate + '%</p></li>';
				}
			} else {
			    //json 遍历
				for (ele in data) {
					// 显示按钮
					$('#btnList').css('display','');
					
					var _html = '';
					for (ele in data) {
						if (detail == 0) {
							var dayBzamt = mdata.format.number(data[ele].dayBzamt, 2, ".", ",");
							var dayAmt = mdata.format.number(data[ele].dayAmt, 2, ".", ",");
							_html = _html + `<li><p>${data[ele].name}</p><p class="ui-li-aside">${dayAmt}/${dayBzamt}</p></li>`;
							//_html = _html + '<li><p>' + data[ele].name +'</p><p class="ui-li-aside">' + dayAmt + '/' + dayBzamt + '%</p></li>';
						} else if (detail == 1) {
							var monRate = mdata.format.number(data[ele].monRate, 2, ".", ",");
							var monBzamt = mdata.format.number(data[ele].monBzamt, 2, ".", ",");
							var monBzamtRate = mdata.format.number(data[ele].monBzamtRate, 2, ".", ",");
							_html = _html + `<li><p>${data[ele].name}</p><p class="ui-li-aside">${monBzamt}/${monRate}/${monBzamtRate}</p></li>`;
							//_html = _html + '<li><p>' + data[ele].name +'</p><p class="ui-li-aside">' + monBzamt + '/' + monRate + '/' + monBzamtRate + '%</p></li>';
						} else if (detail == 2) {
							var yearRate = mdata.format.number(data[ele].yearRate, 2, ".", ",");
							var yearBzamt = mdata.format.number(data[ele].yearBzamt, 2, ".", ",");
							var yeaBzamtRate = mdata.format.number(data[ele].yeaBzamtRate, 2, ".", ",");
							_html = _html + `<li><p>${data[ele].name}</p><p class="ui-li-aside">${yearBzamt}/${yearRate}/${yeaBzamtRate}</p></li>`
							//_html = _html + '<li><p>' + data[ele].name +'</p><p class="ui-li-aside">' + yearBzamt + '/' + yearRate + '/' + yeaBzamtRate + '%</p></li>';
						}
					}
				}
			}
			_arr.push(_html);
			list.html(_arr.join(""));
			list.listview("refresh");
		}
	},
}